#include <iostream>
#include <string.h>
#include <set>
using namespace std;


int get(int x,int f[]){
	if(f[x] == x)
		return x;
	return f[x]=get(f[x],f);
}


int main(){
	int n,m,k,f;
	cin>>n>>m>>k>>f;
	int fath[n];
	set<int> fs[n];
//	memset(fs,0,sizeof(fs));
	for(int i=0;i<n;i++)
		fath[i] = i;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		a--;
		fs[a].insert(b);
	}
//		cout<<1<<endl;
	for(int i=0;i<f;i++){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		int fa,fb;
		fa = get(a,fath);
		fb = get(b,fath);
		fath[fa] = fb;
		fs[fb].insert(fs[fa].begin(),fs[fa].end());
	}
	
//	for(int i=0;i<n;i++)
//		cout<<fs[i]<<" ";
//	cout<<endl;
//	
//	for(int i=0;i<n;i++)
//		cout<<fath[i]<<" ";
//	cout<<endl;
	
	
	int p=-1;
	for(int i=0;i<n;i++){
		if(fath[i] == i){
			if(p == -1)
				p = fs[i].size();
			if(p > fs[i].size())
				p = fs[i].size();
		}
	}
	cout<<(p+k>n?n:p+k);
	return 0;
}
